import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Category from '../views/Category.vue'
import Shopcar from '../views/Shopcar.vue'
import My from '../views/My.vue'
import Login from '../views/Login.vue'
import Register from '../views/Register.vue'
import Good from '../views/Goods/GoodList.vue'
import GoodInfo from '../views/Goods/GoodInfo.vue'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/home'
  },
  {
    path: '/home',
    component: Home,
    meta: { title: '主页' }
  },
  {
    path: '/category',
    component: Category,
    meta: { title: '分类' }
  },
  {
    path: '/shopcar',
    component: Shopcar,
    meta: { title: '购物车' }
  },
  {
    path: '/my',
    component: My,
    meta: { title: '我的' }
  },
  {
    path: '/my/login',
    component: Login,
    meta: { title: '登录' }
  },
  {
    path: '/my/register',
    component: Register,
    meta: { title: '注册' }
  },
  {
    path: '/GoodList/:category_id',
    component: Good,
    props: true,
    meta: { title: '商品列表' }
  },
  {
    path: '/GoodInfo/:id',
    name: 'GoodInfo',
    component: GoodInfo,
    props: true,
    meta: { title: '商品详情' }
  }

]

const router = new VueRouter({
  routes,
  linkActiveClass: 'mui-active'
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})
export default router
